/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.sesame.domain.Album;
import com.sesame.domain.Collect;
import com.sesame.domain.Guestbook;
import com.sesame.domain.Image;
import com.sesame.domain.User;
import com.sesame.service.AlbumService;
import com.sesame.service.ContactService;
import com.sesame.service.PageService;
import com.sesame.service.UserService;
import com.sesame.toolkit.Page;

/**
 * @author voidman
 * 
 */
public class ShowAllAlbumController extends AbstractController {

    private AlbumService albumService;
    private PageService pageService;

    public void setPageService(PageService pageService) {
        this.pageService = pageService;
    }

    public void setAlbumService(AlbumService albumService) {
        this.albumService = albumService;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        Integer userId = (Integer) request.getSession().getAttribute("userId");

        String currentPage = request.getParameter("page");

        Page page = pageService.paging(request, currentPage);
        page.setRecordCount(albumService.getAlbumCount(userId));
        page.setId(userId);

        List<Album> albumList = albumService.listAllAlbum(page);

        Map model = new HashMap();
        model.put("albumList", albumList);
        model.put("page", page);

        return new ModelAndView("showAllAlbum", model);
    }

}